//
//  MainController03.m
//  PosApp
//
//  Created by 刘萍 on 2018/8/31.
//  Copyright © 2018年 李英新. All rights reserved.
//

#import "MainController03.h"
#import "MainModel03.h"

#import "NewsViewController.h"
#import "MySetController.h"
#import "MyTXController.h"

#import "MyProfitController.h"

#import "ShareController.h"
#import "MyRankController.h"
#import "MyTeamController.h"
#import "PosOrderController.h"
#import "MyCodeController.h"

#import "CardRecordController.h"
#import "NewPersonController.h"
#import "LianXiKeFuController.h"
//#import "PosApp-Swift.h"
#import "RouterManager.h"

@interface MainController03 ()

@property (weak, nonatomic) IBOutlet UILabel *NewsNumb;

@property (weak, nonatomic) IBOutlet UIView *ThreeMainView01;
@property (weak, nonatomic) IBOutlet UIImageView *UserHeadImage;
@property (weak, nonatomic) IBOutlet UILabel *UserName;
@property (weak, nonatomic) IBOutlet UIImageView *UserTypeImage;

@property (weak, nonatomic) IBOutlet UILabel *AllShouYi;
@property (weak, nonatomic) IBOutlet UILabel *TiXianPrice;

@property (weak, nonatomic) IBOutlet UIView *ThreeMainView02;
@property (weak, nonatomic) IBOutlet UIView *ThreeMainView03;
@property (weak, nonatomic) IBOutlet UIView *ThreeMainView04;

@property (weak, nonatomic) IBOutlet UIView *ThreeOtherView01;
@property (weak, nonatomic) IBOutlet UIView *ThreeOtherView02;
@property (weak, nonatomic) IBOutlet UIView *ThreeOtherView03;
@property (weak, nonatomic) IBOutlet UIView *ThreeOtherView04;
@property (weak, nonatomic) IBOutlet UIView *ThreeOtherView05;
@property (weak, nonatomic) IBOutlet UIView *ThreeOtherView06;
@property (weak, nonatomic) IBOutlet UIView *ThreeOtherView07;
@property (weak, nonatomic) IBOutlet UIView *ThreeOtherView08;
@property (weak, nonatomic) IBOutlet UIView *ThreeOtherView09;

@property (strong, nonatomic) MainModel03 * model;

@end

@implementation MainController03

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [self UpLoadDataOfMainController03];

}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handleNotification:) name:[RouterManager alipaySuccessNotificationName] object:nil];
    
    self.NewsNumb.layer.cornerRadius = self.NewsNumb.bounds.size.height/2;
    self.NewsNumb.layer.masksToBounds = YES;
    self.UserHeadImage.layer.cornerRadius = self.UserHeadImage.bounds.size.height/2;
    self.UserHeadImage.layer.masksToBounds = YES;
    
    self.ThreeMainView01.layer.shadowColor = [UIColor colorWithRed:206/255.0 green:205/255.0 blue:205/255.0 alpha:0.75].CGColor;
    self.ThreeMainView01.layer.shadowOffset = CGSizeMake(0,1);
    self.ThreeMainView01.layer.shadowOpacity = 1;
    self.ThreeMainView01.layer.shadowRadius = 25;
    self.ThreeMainView01.layer.cornerRadius = 4;
    
    self.ThreeMainView02.layer.shadowColor = [UIColor colorWithRed:225/255.0 green:225/255.0 blue:226/255.0 alpha:0.68].CGColor;
    self.ThreeMainView02.layer.shadowOffset = CGSizeMake(0,1);
    self.ThreeMainView02.layer.shadowOpacity = 1;
    self.ThreeMainView02.layer.shadowRadius = 5;
    self.ThreeMainView02.layer.cornerRadius = 4;
    
    self.ThreeMainView03.layer.shadowColor = [UIColor colorWithRed:225/255.0 green:225/255.0 blue:226/255.0 alpha:0.68].CGColor;
    self.ThreeMainView03.layer.shadowOffset = CGSizeMake(0,1);
    self.ThreeMainView03.layer.shadowOpacity = 1;
    self.ThreeMainView03.layer.shadowRadius = 5;
    self.ThreeMainView03.layer.cornerRadius = 4;
    
    self.ThreeMainView04.layer.shadowColor = [UIColor colorWithRed:225/255.0 green:225/255.0 blue:226/255.0 alpha:0.68].CGColor;
    self.ThreeMainView04.layer.shadowOffset = CGSizeMake(0,1);
    self.ThreeMainView04.layer.shadowOpacity = 1;
    self.ThreeMainView04.layer.shadowRadius = 5;
    self.ThreeMainView04.layer.cornerRadius = 4;
    
    self.ThreeOtherView01.tag = 100;
    self.ThreeOtherView02.tag = 101;
    self.ThreeOtherView03.tag = 102;
    self.ThreeOtherView04.tag = 103;
    self.ThreeOtherView05.tag = 104;
    self.ThreeOtherView06.tag = 105;
    self.ThreeOtherView07.tag = 106;
    self.ThreeOtherView08.tag = 107;
    self.ThreeOtherView09.tag = 108;
    
    for (int i = 0; i < 9; i++) {
        UITapGestureRecognizer * ViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ClickOnOtherView:)];
        UIView * TapView = [self.view viewWithTag:100+i];
        [TapView addGestureRecognizer:ViewTap];
    }
    
}

- (void)handleNotification:(NSNotification *)notification{
    if (notification.name == [RouterManager alipaySuccessNotificationName]){
        [self UpLoadDataOfMainController03];
    }
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

- (void)UpLoadDataOfMainController03{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc] init];
    [dic setObject:KUseriPhone forKey:@"phone"];
    
    [MainObjectWay PostWithMethod:@"index" andAction:@"User" andAddParam:YES parameters:dic success:^(id responseObject) {
        NSLog(@"返回的我的数据 = %@",responseObject);
        if ([MainObjectWay IsSucceedWithCode:responseObject[@"code"]]) {
            NSMutableDictionary * dic = responseObject[@"data"];
            MainModel03 * model = [MainModel03 mj_objectWithKeyValues:dic];
            self.model = model;
            [self CreateMainHeadView];
            NSString * UserImage = [NSString stringWithFormat:@"%@",self.model.member_list_avatar];
            SetKUserImage(UserImage);
            NSString * UserName = [NSString stringWithFormat:@"%@",self.model.member_list_nick];
            SetKUserName(UserName);
            
        }
    } failure:^(NSError *error) {
        NSLog(@"错误信息 = %@",error);
    }];
}

- (void)CreateMainHeadView{
    [self.UserHeadImage sd_setImageWithURL:[NSURL URLWithString:self.model.member_list_avatar] placeholderImage:[UIImage imageNamed:@"MainZWImage"]];
    self.UserName.text = [NSString stringWithFormat:@"%@",self.model.member_list_nick];
    SetKUserName(self.UserName.text);
    
    //iosHDPI
    NSString * typeImageName = [NSString stringWithFormat:@"UserTypeImage0%@%@",self.model.member_list_group,self.model.member_list_goldvip];
    
    self.UserTypeImage.image = [UIImage imageNamed:typeImageName];
//    if ([self.model.member_list_group intValue] == 2 && [self.model.member_list_goldvip intValue] == 1) {
//        self.UserTypeImage.image = [UIImage imageNamed:@"iosHDPI"];
//    }
    
    
    self.AllShouYi.text = [NSString stringWithFormat:@"￥%@",self.model.member_list_income];
    self.TiXianPrice.text = [NSString stringWithFormat:@"￥%@",self.model.member_list_blance];
    
    
}


- (void)ClickOnOtherView:(UITapGestureRecognizer *)tap{
    NSLog(@"==== %ld",tap.view.tag);
    switch (tap.view.tag) {
        case 100:
            {
                //分享推广界面
                ShareController * ShareC = [[ShareController alloc] init];
                [self.navigationController pushViewController:ShareC animated:YES];
            }
            break;
        case 101:
            {
                //我要升级
                UIStoryboard * sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                UIViewController * vc = [sb instantiateViewControllerWithIdentifier:@"VCUpdate"];
                [self.navigationController pushViewController:vc animated:true];
                
                
           
            }
            break;
        case 102:
            {
                //我的团队
                MyTeamController * TeamC = [[MyTeamController alloc] init];
                [self.navigationController pushViewController:TeamC animated:YES];
            }
            break;
        case 103:
            {
                //我的POS机
                PosOrderController * OrderC = [[PosOrderController alloc] init];
                [self.navigationController pushViewController:OrderC animated:YES];
            }
            break;
        case 104:
            {
                //积分订单
                
                MyCodeController * CodeC = [[MyCodeController alloc] init];
                [self.navigationController pushViewController:CodeC animated:YES];
            }
            break;
        case 105:
            {
                //申卡记录
                [self ShowAlter];
//                CardRecordController * CardC = [[CardRecordController alloc] init];
//                [self.navigationController pushViewController:CardC animated:YES];
            }
            break;
        case 106:
            {
                //新手指引
                [self ShowAlter];
//                NewPersonController * NewC = [[NewPersonController alloc] init];
//                [self.navigationController pushViewController:NewC animated:YES];
            }
            break;
        case 107:
            {
                //合作关系
//                [self ShowAlter];
                LianXiKeFuController * LianXiC = [[LianXiKeFuController alloc] init];
                [self.navigationController pushViewController:LianXiC animated:YES];
            }
            break;
        case 108:
            {
                //联系客服
                LianXiKeFuController * LianXiC = [[LianXiKeFuController alloc] init];
                [self.navigationController pushViewController:LianXiC animated:YES];
            }
            break;
        default:
            break;
    }
}

- (IBAction)ClickOnLeftBtnOfMainController03:(id)sender {
    NewsViewController * NewsC = [[NewsViewController alloc] init];
    [self.navigationController pushViewController:NewsC animated:YES];
}

- (IBAction)ClickOnRightBtnOfMainController03:(id)sender {
    MySetController * SetC = [[MySetController alloc] init];
    [self.navigationController pushViewController:SetC animated:YES];
}

- (IBAction)ClickOnBtnToLookSY:(id)sender {
    MyProfitController * ProfitC = [[MyProfitController alloc] init];
    [self.navigationController pushViewController:ProfitC animated:YES];
}
- (IBAction)ClickOnBtnToTX:(id)sender {
    MyTXController * TXC = [[MyTXController alloc] init];
    [self.navigationController pushViewController:TXC animated:YES];
}

- (void)ShowAlter{
    NSString * AlertStr = @"此功能正在开发，请耐心等待";
    UIAlertController * AlertC = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
    
    //修改message
    NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:AlertStr];
    [alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, AlertStr.length)];
    [alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(0, AlertStr.length)];
    [AlertC setValue:alertControllerMessageStr forKey:@"attributedMessage"];
    
    [AlertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"");
    }]];
    
    [self presentViewController:AlertC animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
